package com.alstudio.ui.module.setting;

import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;

import com.alstudio.app.ALLocalEnv;
import com.alstudio.module.xmpp.request.ALUiXmppRequestCreator;
import com.alstudio.ui.base.TitleBarActivity;
import com.alstudio.view.toast.MyToastUtil;
import com.loovee.imaohu.R;

public class FeedBackActivity extends TitleBarActivity implements TextWatcher {

	private EditText et_comment;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		// 初始化UI界面
		setupView(this, getClass().getSimpleName());
	}

	@Override
	protected void setupView(Context context, String name) {
		// TODO Auto-generated method stub
		super.setupView(context, name);
		setTitleBarContentView(R.layout.feedback_layout);
		et_comment = (EditText) findViewById(R.id.et_comment);
		et_comment.addTextChangedListener(this);
		setCenterTextViewMessage(getString(R.string.TxtFeedBackTitle));
		rightUseImageButton(true);
		setRightButtonImageSrc(R.drawable.friend_title_icon_confirm);

		setRightButtonClickListener(this);
		getRightButton().setEnabled(false);

	}

	@Override
	protected void initData() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		super.onClick(v);
		switch (v.getId()) {
		case R.id.button_right:
			// 右鍵
			invokeSendFeedBack();
			break;
		}

	}
	
	/* (non-Javadoc)
	 * @see com.alstudio.ui.base.TitleBarActivity#invokeRightBtnClick()
	 */
	@Override
	protected void invokeRightBtnClick() {
		// TODO Auto-generated method stub
		super.invokeRightBtnClick();
		invokeSendFeedBack();
	}

	/**
	 * 发送反馈
	 */
	private void invokeSendFeedBack() {
		if (ALLocalEnv.isSendXmppDataEnable()) {
			ALUiXmppRequestCreator.postALUiXmppFeedBack(et_comment.getText()
					.toString());
			showFinishActivityAlertDialog(getString(R.string.TxtFeedBackSuccess));
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.text.TextWatcher#afterTextChanged(android.text.Editable)
	 */
	@Override
	public void afterTextChanged(Editable s) {
		// TODO Auto-generated method stub
		boolean isClickAble = TextUtils.isEmpty(s.toString());
		getRightButton().setEnabled(!isClickAble);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.text.TextWatcher#beforeTextChanged(java.lang.CharSequence,
	 * int, int, int)
	 */
	@Override
	public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
			int arg3) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.text.TextWatcher#onTextChanged(java.lang.CharSequence, int,
	 * int, int)
	 */
	@Override
	public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub

	}

}
